a = int(input())
if 1000<=a<10000:
    k = 0
    for i in range(2, a // 2+1):
        if (a % i == 0):
            k = k+1
    if (k <= 0):
        print(a)
    else:
        a = int(str(a)[:3])
        k = 0
        for i in range(2, a // 2 + 1):
            if (a % i == 0):
                k = k + 1
        if (k <= 0):
            print("", a)
        else:
            a = int(str(a)[:2])
            k = 0
            for i in range(2, a // 2 + 1):
                if (a % i == 0):
                    k = k + 1
            if (k <= 0):
                print("", a)
            else:
                a = int(str(a)[0])
                if a == 2 or a == 3 or a==5 or a==7:
                    print(a)
                else:
                    print('0')


else:
    print('0')